package com.jeesite.modules.storage.api;

import com.jeesite.modules.storage.service.*;
import com.jeesite.modules.storage.common.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * 转发Controller
 */
@RestController(value = "apitrans")
@RequestMapping(value = "/api/trans")
@CrossOrigin(origins = "*", maxAge = 3600)
public class TransController extends APIController {

    @Autowired
    private TransActivityService transActivityService;

    /**
     * 活动转发
     * @param memberId 会员Id
     * @param activityId 活动Id
     * @param isBuy 是否购买
     * @param price 加价
     * @return 分享
     */
    @RequestMapping(method = RequestMethod.POST,value = "activity")
    @ResponseBody
    public ServerResponse<Map> activity(@RequestParam(value = "memberId")String memberId,@RequestParam(value = "activityId") String activityId, @RequestParam(value = "isBuy") Boolean isBuy, @RequestParam(value = "price") Double price) throws Exception {
        return ServerResponse.createBySuccess(200,transActivityService.activity(memberId,activityId,isBuy,price));
    }

    /**
     * 选择性转发
     * @param memberId 会员Id
     * @param activityId 活动Id
     * @param goods 商品id【多个直接用','分割】
     * @param isBuy 是否购买
     * @param price 加价
     * @return 分享
     */
    @RequestMapping(method = RequestMethod.POST,value = "selectivity")
    @ResponseBody
    public ServerResponse<Map> selectivity(@RequestParam(value = "memberId")String memberId,@RequestParam(value = "activityId") String activityId,@RequestParam(value = "goods") String goods, @RequestParam(value = "isBuy") Boolean isBuy, @RequestParam(value = "price") Double price) throws Exception {
        return ServerResponse.createBySuccess(200,transActivityService.selectivity(memberId,activityId,getJsonParam(goods),isBuy,price));
    }

    /**
     * 商品转发
     * @param memberId 会员Id
     * @param activityId 活动Id
     * @param goodsId 商品Id
     * @param method 方式【单图、多图】
     * @param isBuy 是否购买
     * @param price 加价
     * @return 分享
     */
    @RequestMapping(method = RequestMethod.POST,value = "goods")
    @ResponseBody
    public ServerResponse<Map> goods(@RequestParam(value = "memberId")String memberId,@RequestParam(value = "activityId") String activityId,@RequestParam(value = "goodsId") String goodsId,@RequestParam(value = "method") String method, @RequestParam(value = "isBuy") Boolean isBuy, @RequestParam(value = "price") Double price) throws Exception {
        return ServerResponse.createBySuccess(200,transActivityService.goods(memberId,activityId,goodsId,method,isBuy,price));
    }

    /**
     * 查询列表【日】
     * @param transMemberId 转发会员Id
     * @param memberId 会员Id
     * @param dayDate 每日日期
     * @param size 每页数量
     * @param page 页码
     * @return 活动列表
     */
    @RequestMapping(method = RequestMethod.GET,value = "day/query")
    @ResponseBody
    public ServerResponse<List<Map>> dayQuery(@RequestParam(value = "transMemberId",required = false)String transMemberId,@RequestParam(value = "memberId")String memberId,@RequestParam(value = "dayDate")String dayDate, @RequestParam(value="size",defaultValue = "10") Integer size, @RequestParam(value="page",defaultValue = "1") Integer page){
        return ServerResponse.createBySuccess(200,transActivityService.getDayBrandList(transMemberId,memberId,dayDate,size,page));
    }

    /**
     * 查询列表【月】
     * @param transMemberId 转发会员Id
     * @param memberId 会员Id
     * @param monthDate 每日日期
     * @param size 每页数量
     * @param page 页码
     * @return 活动列表
     */
    @RequestMapping(method = RequestMethod.GET,value = "month/query")
    @ResponseBody
    public ServerResponse<List<Map>> monthQuery(@RequestParam(value = "transMemberId",required = false)String transMemberId,@RequestParam(value = "memberId")String memberId,@RequestParam(value = "monthDate")String monthDate, @RequestParam(value="size",defaultValue = "10") Integer size, @RequestParam(value="page",defaultValue = "1") Integer page){
        return ServerResponse.createBySuccess(200,transActivityService.getMonthBrandList(transMemberId,memberId,monthDate,size,page));
    }

    /**
     * 重新转发
     * @param transActivityId 转发Id
     * @return 分享
     */
    @RequestMapping(method = RequestMethod.POST,value = "again")
    @ResponseBody
    public ServerResponse<Map> again(@RequestParam(value = "transActivityId") String transActivityId){
        return ServerResponse.createBySuccess(200,transActivityService.again(transActivityId));
    }
}
